<?php
/**
 * Created by PhpStorm.
 * User: wuxiaojie
 * Date: 2018/6/9
 * Time: 15:48
 *
 *
 */

if (!defined('IN_ANWSION')) {
    die;
}

class main extends AWS_CONTROLLER
{

    public function get_access_rule()
    {
        $rule_action['rule_type'] = "white"; //'black'黑名单,黑名单中的检查  'white'白名单,白名单以外的检查

        if ($this->user_info['permission']['visit_explore'] AND $this->user_info['permission']['visit_site']) {
            $rule_action['actions'][] = 'hot';
            $rule_action['actions'][] = 'all';
            $rule_action['actions'][] = 'other';
            $rule_action['actions'][] = 'index';
        }

        return $rule_action;
    }

    public function setup()
    {
//        if (is_mobile() AND !$_GET['ignore_ua_check']) {
//            switch ($_GET['app']) {
//                default:
//                    HTTP::redirect('/m/');
//                    break;
//            }
//        }
    }



    public function index_action()
    {


        //去详情页
        if($_GET['goods']) {

//        $where = array("is_on_sale"=>1,"is_delete"=>0,'is_hot'=>1);
            $where = array();

            $goods_info = $this->model('goods')->get_goods_info_by_gid(intval($_GET['goods']));

            $this->crumb(AWS_APP::lang()->_t($goods_info['goods_name']), '/aomas/shop_info/');
//            相册
            $goods_photos= $this->model('goods')->get_cover('goods', intval($_GET['goods']));
//            颜色
            $goods_style = $this->model('goods')->get_goods_style_list(intval($_GET['goods']));
//型号
            $goods_model = $this->model('goods')->get_goods_model_list(intval($_GET['goods']));

            TPL::assign('goods_photos',$goods_photos);

            TPL::assign('goods_style_list', $goods_style);

            TPL::assign('goods_model_list', $goods_model);

            TPL::assign('goods_info', $goods_info);


            TPL::set_meta('keywords',  $goods_info['goods_name'].'-aomas澳玛仕正品行货');

            TPL::set_meta('description', $goods_info['goods_name'].'-'.$goods_info['goods_brief']. ' - ' . cjk_substr(str_replace("\r\n", ' ', strip_tags('澳玛仕热销商品，正品行货,周边商品')), 0, 128, 'UTF-8', '...'));


            if (is_mobile() AND !$_GET['ignore_ua_check']) {

                TPL::output('aomas/m_shop_info/index');

            }else{

                TPL::output('aomas/shop_info/index');
            }


        }else{

            HTTP::redirect('/product/hot/');
        }
    }


    public function all_action()
    {
        $this->crumb(AWS_APP::lang()->_t('全部宝贝'), '/aomas/all_product/');

        TPL::set_meta('keywords',  '踏步机，椭圆机，按摩椅垫 ，足疗机，颈肩按摩椅，周边商品，按摩枕，划船机-aomas澳玛仕全部商品');

        TPL::set_meta('description', 'aomas澳玛仕全部商品，所有热销商品，正品行货' . ' - ' . cjk_substr(str_replace("\r\n", ' ', strip_tags('跑步机系列、跑步机系列、椭圆机系列、划船机系列、按摩椅系列、足疗机系列、按摩枕系列')), 0, 128, 'UTF-8', '...'));


        $where[] = " is_delete= 0 ";
        $where[] = " is_on_sale = 1 ";
        if($_GET['cat']){
            $where[] = 'cat_id ='.intval($_GET['cat']);
        }
        $cols = "goods_id,cat_id,goods_sn,goods_name,keywords,goods_brief,market_price,shop_price,promote_price,give_integral,sort_order,is_new,is_best,is_hot,is_promote,jd_url,tb_url,cover";
        $cols  = explode(',',$cols);

        $data = $this->model('goods')->get_goods_list_page($cols,$where,' goods_id DESC');
        foreach ($_GET as $key => $val) {
            if (!in_array($key, array('app', 'c', 'act', 'page'))) {
                $url_param[] = $key . '-' . $val;
            }
        }

        $total_rows = $data['total_rows'];
        $goods_list = $data['list'];
        TPL::assign('pagination', AWS_APP::pagination()->initialize(array(
            'base_url' => get_js_url('product/all/') . implode('__', $url_param),
            'total_rows' => $total_rows,
            'per_page' => $this->per_page
        ))->create_links());

        TPL::assign('goods_list', $goods_list);
        TPL::assign('total_rows', $total_rows);
        TPL::assign('category_list',$this->model('system')->fetch_category_data('goods'));
        if (is_mobile() AND !$_GET['ignore_ua_check']) {

            TPL::output('aomas/m_all_product/index');

        }else{
            TPL::output('aomas/all_product/index');

        }


    }

    /**
     * 热销
     * 1.足疗机 4条 （2大 2小）
     * 2.按摩椅垫 2条（2大）
     * 3.按摩枕（2大 2小）
     * 3.踏步机（1大）
     * 4.椭圆机（1大）
     */
    public function hot_action()
    {

        $this->crumb(AWS_APP::lang()->_t('热销宝贝'), '/aomas/hot/');

        TPL::set_meta('keywords',  '热销宝贝->踏步机，椭圆机，按摩椅垫 ，足疗机，颈肩按摩椅，周边商品，按摩枕，划船机-aomas澳玛仕全部热销宝贝');

        TPL::set_meta('description', 'aomas澳玛仕热销宝贝，所有热销商品，正品行货' . ' - ' . cjk_substr(str_replace("\r\n", ' ', strip_tags('澳玛仕健身器材，保健器材')), 0, 128, 'UTF-8', '...'));

        //2	踏步机	goods		0	0
//3	椭圆机	goods		0	0
//4	按摩椅垫	goods		0	0
//5	足疗机	goods		0	0
//6	颈肩按摩椅	goods		0	0
//7	商品周边	goods		0	0
//
////        足疗机
//        $zuliaoji = $this->model('goods')->get_home_goods_list(array('is_on_sale=1','is_hot=1','cat_id=5'),4);
////       按摩椅垫
//        $anmoyidian = $this->model('goods')->get_home_goods_list(array('is_on_sale=1','is_hot=1','cat_id=4'),2);
//
////        按摩枕
//        $anmozhen = $this->model('goods')->get_home_goods_list(array('is_on_sale=1','is_hot=1','cat_id=6'));
//
////        踏步机
//        $tabuji = $this->model('goods')->get_home_goods_list(array('is_on_sale=1','is_hot=1','cat_id=2'));
////        椭圆机
//        $tuoyuanji = $this->model('goods')->get_home_goods_list(array('is_on_sale=1','is_hot=1','cat_id=3'));
//
////        var_dump($zuliaoji);
//        TPL::assign('zuliaoji1',array_splice($zuliaoji,0,2));
//
//
//        TPL::assign('zuliaoji2',array_splice($zuliaoji,0,2));
//
//
//        TPL::assign('anmozhen1',array_splice($anmozhen,0,2));
//        TPL::assign('anmozhen2',array_splice($anmozhen,0,2));
//
//        TPL::assign('anmoyidian',$anmoyidian);
//        TPL::assign('tabuji',$tabuji);
//        TPL::assign('tuoyuanji',$tuoyuanji);


        $special  =$this->model('goodsSpecial')->get_special_info_by_id(1);

        TPL::assign('special',$special);


        if (is_mobile() AND !$_GET['ignore_ua_check']) {

            TPL::output('aomas/m_hot/index');
        }else{
            TPL::output('aomas/hot/index');

        }

    }

    public function other_action()
    {

        $this->crumb(AWS_APP::lang()->_t('周边商品'), '/aomas/hot/');


        TPL::set_meta('keywords',  '周边商品->踏步机，椭圆机，按摩椅垫 ，足疗机，颈肩按摩椅，周边商品，按摩枕，划船机-aomas澳玛仕全部周边商品');

        TPL::set_meta('description', 'aomas澳玛仕热销宝贝，所有热销商品，正品行货,周边商品' . ' - ' . cjk_substr(str_replace("\r\n", ' ', strip_tags('澳玛仕健身器材，保健器材')), 0, 128, 'UTF-8', '...'));

        $where[] ="is_on_sale = 1";
        $where[] ="cat_id  = 7";

        $goods_list = $this->model('goods')->fetch_page('goods', implode(' AND ', $where), 'goods_id DESC', $_GET['page'], $this->per_page);

        $total_rows = $this->model('goods')->found_rows();

        $url_param = array();

        foreach ($_GET as $key => $val) {
            if (!in_array($key, array('app', 'c', 'act', 'page'))) {
                $url_param[] = $key . '-' . $val;
            }
        }

        TPL::assign('pagination', AWS_APP::pagination()->initialize(array(
            'base_url' => get_js_url('product/all/') . implode('__', $url_param),
            'total_rows' => $total_rows,
            'per_page' => $this->per_page
        ))->create_links());

        TPL::assign('goods_list', $goods_list);
        TPL::assign('total_rows', $total_rows);
        if (is_mobile() AND !$_GET['ignore_ua_check']) {

            TPL::output('aomas/m_all_product/index');
        }else{
            TPL::output('aomas/all_product/index');

        }

    }

}